﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using SharppiFlowEditor.models;

namespace SharppiFlowEditor.views
{
    public class ConnectorPropertiesView : ScrollableControl
    {

        private Label objTypeLabel, objTextLabel, connStartNodeLabel, connEndNodeLabel;
        private TextBox objTextTextBox;
        private ListBox connStartNodeListBox, connEndNodeListBox;
        private Font usedFont;
        private String[] connectorTypes;
        private Button saveButton;

        public Button SaveButton { get { return saveButton; } }

        public String ConnText { get { return objTextTextBox.Text; } }

        public String node1Title { get { return connStartNodeListBox.SelectedItem.ToString(); } }

        

        private Object _selectedGraphObject;
        public Object SelectedGraphObject
        {
            set { _selectedGraphObject = value; }
            get { return _selectedGraphObject; }
        }


        public ConnectorPropertiesView()
        {
            usedFont = new Font(FontFamily.GenericSansSerif, 10.0F);

            this.Dock = DockStyle.Top;

            objTypeLabel = new Label();
            objTypeLabel.Text = "Type";
            objTypeLabel.Font = usedFont;
            objTypeLabel.Location = new Point(2, 110);
            objTypeLabel.Width = 55;
            objTextLabel = new Label();
            objTextLabel.Text = "Text";
            objTextLabel.Font = usedFont;
            objTextLabel.Location = new Point(2, 10);
            objTextLabel.Width = 55;

            connStartNodeLabel = new Label();
            connStartNodeLabel.Text = "Start node";
            connStartNodeLabel.Font = usedFont;
            connStartNodeLabel.Location = new Point(2, 40);
            connStartNodeLabel.Width = 55;
            connStartNodeLabel.Height = 35;
            connEndNodeLabel = new Label();
            connEndNodeLabel.Text = "End node";
            connEndNodeLabel.Font = usedFont;
            connEndNodeLabel.Location = new Point(2, 80);
            connEndNodeLabel.Width = 55;
            connEndNodeLabel.Height = 35;

            objTextTextBox = new TextBox();
            objTextTextBox.Font = usedFont;
            objTextTextBox.Location = new Point(60, 10);
            objTextTextBox.Width = 100;

            connStartNodeListBox = new ListBox();
            connStartNodeListBox.Location = new Point(60, 40);
            connStartNodeListBox.Size = new Size(100, 35);
            connStartNodeListBox.SelectionMode = SelectionMode.One;
            connEndNodeListBox = new ListBox();
            connEndNodeListBox.Location = new Point(60, 80);
            connEndNodeListBox.Size = new Size(100, 35);
            connEndNodeListBox.SelectionMode = SelectionMode.One;

            connectorTypes = new String[] { "Connector" };

            //objTextTextBox.Enabled = false;
            //objTypeListBox.Enabled = false;

            saveButton = new Button();
            saveButton.Text = "Save";
            saveButton.Location = new Point(110, 120);
            saveButton.Size = new Size(50, 25);

            this.Controls.Add(objTextLabel);
            this.Controls.Add(objTextTextBox);
            this.Controls.Add(connStartNodeLabel);
            this.Controls.Add(connStartNodeListBox);
            this.Controls.Add(connEndNodeLabel);
            this.Controls.Add(connEndNodeListBox);
            this.Controls.Add(saveButton);

        }

        // Set SelectedGraphObject-property before calling this.
        public void updatePropertiesView()
        {
            if (_selectedGraphObject is Connector)
            {
                Connector conn = (Connector)_selectedGraphObject;
                objTextTextBox.Text = conn.Text;
                connStartNodeListBox.Items.Clear();
                connStartNodeListBox.Items.AddRange(new String[] { conn.Node1.Title, conn.Node2.Title });
                connStartNodeListBox.SelectedIndex = 0;
                connEndNodeListBox.Items.Clear();
                connEndNodeListBox.Items.AddRange(new String[] { conn.Node1.Title, conn.Node2.Title });
                connEndNodeListBox.SelectedIndex = 1;
            }
        }

        public void clearPropertiesView()
        {
            objTextTextBox.Text = "";
            connStartNodeListBox.Items.Clear();
            connEndNodeListBox.Items.Clear();
        }

    }
}
